<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Site/classes/PhpFox_ComponentStyleContent.class.php, $Author:  $ */



/** Component for editing style file
 * @version $Id: PhpFox_ComponentStyleContent.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.site
 *   
 */
class PhpFox_Mod_Site_ComponentStyleContent extends BaseComponent
{
    function process()
    {
        $oReq = &App::getRequest();
        $oTpl = &$this->_oModule->getTemplate();
        $oAdminService = &App::getModuleService('Admin', 'Admin');
        /* @var $oAdminService PhpFox_Mod_Admin_ServiceAdmin */
        $oCssItem = &$this->_oModule->getItem('Css');
        /* @var $oCssItem PhpFox_Mod_Site_ItemCss */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        if (!$oSecurityService->hasStaffPerm('MENU_css_default'))
        {
            App::gotoUrl('admin.main');
        }

        $iStyleId = $oReq->getInt('id');
        if ($oReq->getAction() == 'save')
        {
            if ($oCssItem->load($iStyleId))
            {
                $sStylePath = App::getParam('style.path').$oCssItem->aData['file'].'/';
                $sStylePath .= 'style.css';
                $aParams = array
                (
                    'id' => $iStyleId,
                );
                if ($oAdminService->writeToFile($oReq->get('content'), $sStylePath))
                {
                    App::gotoUrl('admin.popup.styleeditor', $aParams, App::format('Mod_Admin.mess.file_writed'), false, 'editor');
                }
                App::gotoUrl('admin.popup.styleeditor', $aParams, App::format('Mod_Admin.error.file_not_writed'), true, 'editor');
            }
            exit();
        }
        if ($oCssItem->load($iStyleId))
        {
            $sStylePath = App::getParam('style.path').$oCssItem->aData['file'].'/';
            $sStylePath .= 'style.css';
            $oTpl->assign(array(
                'iStyleId'  => $iStyleId,
                'sFilePath' => $oCssItem->aData['file'].'/style.css',
                'sContent'  => $oAdminService->readFromFile($sStylePath),
                'bWritable' => CFile::isWritable($sStylePath),
            ));
            return $oTpl->fetch('StyleContent.html');
        }
        exit();
    }
}
?>